﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using _3Dsoundor2Dgraphor.Sound;

namespace _3Dsoundor2Dgraphor.Graphics
{
	class Root : Element
	{

		public List<Element> objects;
		public Player player;

		public SoundSystem soundSystem;

		public Root(int _sceneX, int _sceneY, int _sceneW, int _sceneH)
		{
			sceneX = _sceneX;
			sceneY = _sceneY;
			sceneH = _sceneH;
			sceneW = _sceneW;
			objects = new List<Element>();
			player = new Player(_sceneX + _sceneW / 2, _sceneY + sceneH/2,5);

			soundSystem = new SoundSystem();
		}


		public override void draw(System.Drawing.Graphics output)
		{
			if (player != null) player.draw(output);
			if (objects != null)
			{
				for (int i = 0; i<objects.Count; i++)
				{
					objects[i].draw(output);
				}
			}
		}


		public void refresh(System.Drawing.Graphics output)
		{
			draw(output);
		}

		public void movePlayer(int X, int Y)
		{
			player.move(X, Y);
		}

		public void action()
		{
			if (objects != null)
			{
				for (int i = 0; i < objects.Count; i++)
				{
					objects[i].action(player._position);
				}
			}
		}
		public void addObject(Element elem)
		{
			elem._position.X += sceneX;
			elem._position.Y += sceneY;
			if (objects != null) objects.Add(elem);
		}

		public override void stopAction(PointF position)
		{
			if (objects != null)
			{
				for (int i = 0; i < objects.Count; i++)
				{
					objects[i].stopAction(player._position);
				}
			}
		}
	}
}
